﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Server.communication;
using System.Runtime.Serialization;
using MySql.Data.MySqlClient;
using System.Windows.Forms;

namespace Server.Processes
{
    [DataContract]
    public class AddUserRequest : AbstractRequest
    {

        [DataMember]
        private string _user;
        [DataMember]
        private string _pass;

        public AddUserRequest(string user, string pass)
        {
            _user = user;
            _pass = pass;
        }




        public override AbstractResponse handleRequest()
        {
            //actually talk to DB
            MySqlConnection sc = new MySqlConnection(" server=localhost;user id=root;password=nir7424394;database=katom;persistsecurityinfo=True ");
            MySqlCommand cmd;

            MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder();

            sc.Open();
            cmd = new MySqlCommand("Insert into user (userID,Password,Privilage) values('" + _user + "','" + _pass + "','ok')", sc);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Update Successfull to the Database");
            sc.Close();

            AbstractResponse response = new AddUserResponse(AddUserResponse.SUCCESS);
            return response;
        }
    }
}
